package reduce.fz.com.reduce.util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import reduce.fz.com.reduce.R;

/**
 * Created by qingshengzheng on 15/7/5.
 */
public class DotOper {
    private int selectRsid;
    private int unselectRsid;
    private int wh;
    private Context context;
    private LinearLayout linearLayout;
    private List<View> dotList = new ArrayList<View>();


    public DotOper( int selectRsid, int unselectRsid, int wh, LinearLayout layout) {

        this.selectRsid = selectRsid;
        this.unselectRsid = unselectRsid;
        this.wh = wh;
        this.linearLayout = layout;
        this.context = linearLayout.getContext();

    }

    public void select(int index) {
        for (int i = 0; i < dotList.size(); i++) {
            if (index == dotList.size() - 1) {
                dotList.get(i).setBackgroundResource(this.selectRsid);
            } else {
                dotList.get(i).setBackgroundResource(this.unselectRsid);
            }
        }
    }

    /**
     * @param index    选中index(从零开始)
     * @param size(长度)
     */
    public List<View> initDot(int index, int size) {
        linearLayout.removeAllViews();
        for (int i = 0; i < size; i++) {
            TextView v = new TextView(context);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(wh, wh);
            layoutParams.setMargins(wh / 3, 0, wh / 3, 0);
            if (index == (size - 1)) {
                v.setBackgroundResource(R.drawable.dot_item_select_point);
            } else {
                v.setBackgroundResource(R.drawable.dot_item_unselect_point);
            }
            linearLayout.addView(v);
            dotList.add(v);

        }
        return dotList;
    }
}
